<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>02.回调函数形式的ref</title>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="../js/prop-types.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
        class DemoComponent extends React.Component {
            alertMessage = () => {
                const {input1} = this
                alert(input1.value)
            }

            alertMessageOnBlur = () => {
                const {input2} = this
                alert(input2.value)
            }
            render(){
                console.log(this)
                return (
                    <div>
                        <input type="text" ref={(c) => {this.input1 = c}}/>
                        <button onClick={this.alertMessage}>Click this to alert message before</button>
                        <input type="text" placeholder='Alert message when out of focus' ref={c => this.input2 = c} onBlur = {this.alertMessageOnBlur}/>
                    </div>
                )
            }
        }

        ReactDOM.render(<DemoComponent/>, document.querySelector('#app'))
    </script>
</body>
</html>